import { Component, OnInit, Input, OnDestroy } from '@angular/core'
import { Task, ETaskOperation } from '@shared/interfaces/task'
import { StoreFull } from '@shared/interfaces/store'
import { DataService } from '@shared/services/data.service'
import { PageService } from '@shared/services/page.service'

@Component({
  selector: 'app-store-task-detail',
  templateUrl: './store.component.html',
})
export class StoreTaskDetailComponent implements OnInit, OnDestroy {
  origStoreFull: StoreFull
  storeFull: StoreFull
  ETaskOperation = ETaskOperation

  @Input() task: Task
  constructor(
    private dataService: DataService,
    private pageService: PageService,
  ) {}

  ngOnInit() {
    this.storeFull = this.task.data.storeData
    this.origStoreFull = this.task.data.origStoreData
    this.pageService.setStoreDisplayInTask(true)
    this.dataService.setStoreFull(this.storeFull)
    this.setIntStoreCode()
  }

  setIntStoreCode(): void {
    this.dataService.setIntStoreCode(this.storeFull.store.common.intStoreCode)
  }

  ngOnDestroy() {
    this.dataService.resetStoreFull()
    this.pageService.setStoreDisplayInTask(false)
    this.dataService.resetIntStoreCode()
  }
}
